@echo off
:: Script to download and install TeamViewer on Windows 11

:: Check if running as administrator
net session >nul 2>&1
if %errorLevel% == 0 (
    echo Running as administrator...
) else (
    echo Please run this script as administrator!
    pause
    exit /b
)

:: Set the download URL for TeamViewer
set TEAMVIEWER_URL=https://download.teamviewer.com/download/TeamViewer_Setup.exe

:: Set the path to save the installer (Windows 11 default download directory)
set DOWNLOAD_PATH=%USERPROFILE%\Downloads\TeamViewer_Setup.exe

:: Download the TeamViewer installer using PowerShell
echo Downloading TeamViewer installer...
powershell -Command "Invoke-WebRequest -Uri '%TEAMVIEWER_URL%' -OutFile '%DOWNLOAD_PATH%'"

:: Check if the download was successful
if not exist "%DOWNLOAD_PATH%" (
    echo Failed to download TeamViewer installer!
    pause
    exit /b
)

:: Install TeamViewer
echo Installing TeamViewer...
echo Please follow the installation wizard to complete the installation.
start /wait "" "%DOWNLOAD_PATH%"

:: Check if TeamViewer is installed
where teamviewer >nul 2>&1
if %errorLevel% == 0 (
    echo TeamViewer installation completed successfully!
) else (
    echo TeamViewer installation failed!
)

:: Clean up the installer
echo Cleaning up the installer...
del "%DOWNLOAD_PATH%"

pause